﻿Public Partial Class Product_Monthly
    Inherits System.Web.UI.Page

    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim lbPage As Label = CType(Master.FindControl("lbPage"), Label)
            lbPage.Text = "PRODUCT MONTHLY REPORT"
            For i As Integer = 0 To 4
                With ddlYear
                    .Items.Insert(i, Date.Now.AddYears(i - 2).Year)
                    .Items(i).Value = Date.Now.AddYears(i - 2).Year
                End With
            Next
            ddlYear.SelectedIndex = 2
            If Not (ddlMonth.Items.FindByValue(Date.Now.Month) Is Nothing) Then
                ddlMonth.SelectedValue = Date.Now.Month
            End If

        End If
    End Sub
    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "M")
        End If
    End Sub


    Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim service As New _ReportingService.Report

        Dim optWindow As String = "left=0,top=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no"
        Dim Orientation As Boolean = True
        Dim ReportName As String = String.Empty
        Dim reportDataSource As String = String.Empty
        Dim paraName As String = String.Empty
        Dim paraValue As String = String.Empty
        Dim reportType As String = String.Empty
        Dim urlDisplay As String = String.Empty
        Dim dsReport As New DataSet
        Dim LCT_TIME As String = "0"
        Dim LCT_LOAD As String = "0"
        Dim LCT_DISCH As String = "0"
        Dim LCT_VOY_LOAD As String = "0"
        Dim LCT_VOY_DISCH As String = "0"
        Dim BCT_TIME As String = "0"
        Dim BCT_LOAD As String = "0"
        Dim BCT_DISCH As String = "0"
        Dim BCT_VOY_LOAD As String = "0"
        Dim BCT_VOY_DISCH As String = "0"

        Dim StandardTime As String = ""
        Dim ActualTime As String = ""
        dsReport.Tables.Add(Get_Value(LCT_TIME, LCT_LOAD, LCT_DISCH, BCT_TIME, BCT_LOAD, BCT_DISCH, LCT_VOY_LOAD, LCT_VOY_DISCH, BCT_VOY_LOAD, BCT_VOY_DISCH))
        dsReport.AcceptChanges()

        'Dim row = From t In dsReport.Tables(0).AsEnumerable() Select stdTime = t("STD_TIME")
        Dim stdTimeList As New List(Of Long)
        Dim actTimeList As New List(Of Long)
        For Each row As DataRow In dsReport.Tables(0).Rows
            Dim st As String = row("STD_TIME").ToString() '.Split(":")
            If (st <> "") Then
                Dim sTime() As String = st.Split(":")
                Dim hr As Integer = CInt(sTime(0))
                Dim min As Integer = CInt(sTime(1))
                Dim timeSpan As New TimeSpan(hr, min, 0)
                stdTimeList.Add(timeSpan.Ticks)
            End If

            Dim ac As String = row("ACT_TIME").ToString()
            If (ac <> "") Then
                Dim acTime() As String = ac.Split(":")
                Dim hr As Integer
                Try
                    hr = CInt(acTime(0))
                Catch ex As Exception
                    hr = 0
                End Try
                Dim min As Integer = CInt(acTime(1))
                actTimeList.Add(New TimeSpan(hr, min, 0).Ticks)
            End If
        Next

        Dim sumStd = New TimeSpan(stdTimeList.Sum())
        Dim S_STD_TIME As String = sumStd.TotalHours.ToString().Split(".")(0) & ":" & sumStd.Minutes.ToString("##00")

        Dim sumAct = New TimeSpan(actTimeList.Sum())
        Dim S_ACT_TIME As String = sumAct.TotalHours.ToString().Split(".")(0) & ":" & sumAct.Minutes.ToString("##00")

        ReportName = "Transfer.rdlc"
        ' dsReport = New DataSet
        reportDataSource = "Transfer_Value_Value"
        LCT_TIME = (CInt(LCT_TIME) \ 60) & ":" & (CInt(LCT_TIME) Mod 60).ToString("00")
        BCT_TIME = (CInt(BCT_TIME) \ 60) & ":" & (CInt(BCT_TIME) Mod 60).ToString("00")
        LCT_LOAD = FormatNumber(LCT_LOAD, 3)
        LCT_DISCH = FormatNumber(LCT_DISCH, 3)
        BCT_LOAD = FormatNumber(BCT_LOAD, 3)
        BCT_DISCH = FormatNumber(BCT_DISCH, 3)
        paraName = "Month;S_LCT_TIME;S_LCT_LOAD;S_LCT_DISCH;S_BCT_TIME;S_BCT_LOAD;S_BCT_DISCH;S_LCT_VOY_LOAD;S_LCT_VOY_DISCH;S_BCT_VOY_LOAD;S_BCT_VOY_DISCH;S_STD_TIME;S_ACT_TIME"
        paraValue = ddlMonth.SelectedItem.Text & " " & CInt(ddlYear.SelectedValue) & ";" & LCT_TIME & ";" & LCT_LOAD & ";" & LCT_DISCH & ";" & BCT_TIME & ";" & BCT_LOAD & ";" & BCT_DISCH & ";" & LCT_VOY_LOAD & ";" & LCT_VOY_DISCH & ";" & BCT_VOY_LOAD & ";" & BCT_VOY_DISCH & ";" & S_STD_TIME & ";" & S_ACT_TIME
        Orientation = True
        reportType = radioType.SelectedValue

        urlDisplay = service.CreateReporting(dsReport, reportDataSource, reportType, ReportName, paraName, paraValue, Orientation, "")

        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "window.open('" + urlDisplay + "','_blank','" + optWindow + "');", True)
    End Sub

    Private Function Get_Value(ByRef LCT_TIME As String, ByRef LCT_LOAD As String, ByRef LCT_DISCH As String, ByRef BCT_TIME As String, ByRef BCT_LOAD As String, ByRef BCT_DISCH As String, ByRef LCT_VOY_LOAD As String, ByRef LCT_VOY_DISCH As String, ByRef BCT_VOY_LOAD As String, ByRef BCT_VOY_DISCH As String) As DataTable
        Dim dt As DataTable = CreateData()
        Dim dtLi As DataTable = clsGet.Get_PRODUCT_monthly("L", ddlYear.SelectedValue & CInt(ddlMonth.SelectedValue).ToString("00") & "00", ddlYear.SelectedValue & CInt(ddlMonth.SelectedValue).ToString("00") & "32")
        Dim dtBu As DataTable = clsGet.Get_PRODUCT_monthly("B", ddlYear.SelectedValue & CInt(ddlMonth.SelectedValue).ToString("00") & "00", ddlYear.SelectedValue & CInt(ddlMonth.SelectedValue).ToString("00") & "32")
        Dim dr As DataRow
        Dim count As Integer = 0
        Dim CP As Integer = 1
        If (dtLi.Rows.Count > dtBu.Rows.Count) Then
            Dim code As String = ""
            Dim Name As String = ""
            Dim Load As Double = 0.0
            Dim DIsch As Double = 0.0
            Dim Time As Long = 0
            Dim STD_Time As String = ""
            Dim ACT_Time As String = ""
            For Each d As DataRow In dtLi.Rows
                If (d.Item("Product_no") & "" <> code) Then
                    If (code <> "") Then
                        dr = dt.NewRow()
                        dr.Item("LCT_P_CODE") = code
                        dr.Item("LCT_P_NAME") = Name
                        dr.Item("LCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                        LCT_TIME = CLng(LCT_TIME) + Time
                        If (Load <> 0.0) Then
                            dr.Item("LCT_LOAD") = FormatNumber(Load, 3)
                            LCT_LOAD = CDbl(LCT_LOAD) + Load
                        Else
                            dr.Item("LCT_LOAD") = "-"
                        End If
                        If (DIsch <> 0.0) Then
                            dr.Item("LCT_DISCH") = FormatNumber(DIsch, 3)
                            LCT_DISCH = CDbl(LCT_DISCH) + DIsch
                        Else
                            dr.Item("LCT_DISCH") = "-"
                        End If

                        dr.Item("LCT_VOY") = count

                        dr.Item("STD_TIME") = STD_Time
                        dr.Item("ACT_TIME") = ACT_Time

                        dt.Rows.Add(dr)
                        dt.AcceptChanges()
                    End If
                    code = d.Item("Product_no")
                    count = 0
                    Name = CP & ". " & d.Item("Product_name")
                    Load = 0.0
                    DIsch = 0.0
                    Time = 0
                    STD_Time = d.Item("StandardTime").ToString()
                    ACT_Time = d.Item("ActualTime").ToString()
                    CP += 1
                End If
                If (d.Item("Product_Event") & "" = "L") Then
                    count += 1
                    If (d.Item("LU_BLMT") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        Load += CDbl(d.Item("LU_BLMT"))
                        LCT_VOY_LOAD = CInt(LCT_VOY_LOAD) + 1

                    End If
                Else
                    count += 1
                    If (d.Item("LU_BLMT") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        DIsch += CDbl(d.Item("LU_BLMT"))
                        LCT_VOY_DISCH = CInt(LCT_VOY_DISCH) + 1

                    End If
                End If
            Next
            If (code <> "") Then
                dr = dt.NewRow()
                dr.Item("LCT_P_CODE") = code
                dr.Item("LCT_P_NAME") = Name
                dr.Item("LCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                LCT_TIME = CLng(LCT_TIME) + Time
                If (Load <> 0.0) Then
                    dr.Item("LCT_LOAD") = FormatNumber(Load, 3)
                    LCT_LOAD = CDbl(LCT_LOAD) + Load
                Else
                    dr.Item("LCT_LOAD") = "-"
                End If
                If (DIsch <> 0.0) Then
                    dr.Item("LCT_DISCH") = FormatNumber(DIsch, 3)
                    LCT_DISCH = CDbl(LCT_DISCH) + DIsch
                Else
                    dr.Item("LCT_DISCH") = "-"
                End If

                dr.Item("LCT_VOY") = count

                dr.Item("STD_TIME") = STD_Time
                dr.Item("ACT_TIME") = ACT_Time

                dt.Rows.Add(dr)
                dt.AcceptChanges()
            End If
            code = ""
            count = 0
            Name = ""
            Load = 0.0
            DIsch = 0.0
            Time = 0

            STD_Time = ""
            ACT_Time = ""

            CP = 1
            Dim cB As Integer = 0
            For Each d As DataRow In dtBu.Rows
                If (d.Item("Product_no") & "" <> code) Then
                    If (code <> "") Then
                        dt.Rows(cB).Item("BCT_P_CODE") = code
                        dt.Rows(cB).Item("BCT_P_NAME") = Name
                        dt.Rows(cB).Item("BCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                        BCT_TIME = CLng(BCT_TIME) + Time
                        If (Load <> 0.0) Then
                            dt.Rows(cB).Item("BCT_LOAD") = FormatNumber(Load, 3)
                            BCT_LOAD = CDbl(BCT_LOAD) + Load
                        Else
                            dt.Rows(cB).Item("BCT_LOAD") = "-"
                        End If
                        If (DIsch <> 0.0) Then
                            dt.Rows(cB).Item("BCT_DISCH") = FormatNumber(DIsch, 3)
                            BCT_DISCH = CDbl(BCT_DISCH) + DIsch
                        Else
                            dt.Rows(cB).Item("BCT_DISCH") = "-"
                        End If

                        dt.Rows(cB).Item("BCT_VOY") = count

                        dt.Rows(cB).Item("STD_TIME") = STD_Time
                        dt.Rows(cB).Item("ACT_TIME") = ACT_Time

                        dt.AcceptChanges()
                        cB += 1
                    End If
                    code = d.Item("Product_no")
                    count = 0
                    Name = CP & ". " & d.Item("Product_name")
                    Load = 0.0
                    DIsch = 0.0
                    Time = 0

                    STD_Time = d.Item("StandardTime").ToString()
                    ACT_Time = d.Item("ActualTime").ToString()

                    CP += 1
                End If
                If (d.Item("Product_Event") & "" = "L") Then
                    count += 1
                    If (d.Item("BU_TRUCK") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        Load += CDbl(d.Item("BU_TRUCK"))
                        BCT_VOY_LOAD = CInt(BCT_VOY_LOAD) + 1

                    End If
                Else
                    count += 1
                    If (d.Item("BU_TRUCK") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        DIsch += CDbl(d.Item("BU_TRUCK"))
                        BCT_VOY_DISCH = CInt(BCT_VOY_DISCH) + 1

                    End If
                End If
            Next
            If (code <> "") Then
                dt.Rows(cB).Item("BCT_P_CODE") = code
                dt.Rows(cB).Item("BCT_P_NAME") = Name
                dt.Rows(cB).Item("BCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                BCT_TIME = CLng(BCT_TIME) + Time
                If (Load <> 0.0) Then
                    dt.Rows(cB).Item("BCT_LOAD") = FormatNumber(Load, 3)
                    BCT_LOAD = CDbl(BCT_LOAD) + Load
                Else
                    dt.Rows(cB).Item("BCT_LOAD") = "-"
                End If
                If (DIsch <> 0.0) Then
                    dt.Rows(cB).Item("BCT_DISCH") = FormatNumber(DIsch, 3)
                    BCT_DISCH = CDbl(BCT_DISCH) + DIsch
                Else
                    dt.Rows(cB).Item("BCT_DISCH") = "-"
                End If

                dt.Rows(cB).Item("BCT_VOY") = count

                dt.Rows(cB).Item("STD_TIME") = STD_Time
                dt.Rows(cB).Item("ACT_TIME") = ACT_Time

                dt.AcceptChanges()
                cB += 1
            End If
        Else
            Dim code As String = ""
            Dim Name As String = ""
            Dim Load As Double = 0.0
            Dim DIsch As Double = 0.0
            Dim Time As Long = 0
            Dim STD_Time As String = ""
            Dim ACT_Time As String = ""
            For Each d As DataRow In dtBu.Rows
                If (d.Item("Product_no") & "" <> code) Then
                    If (code <> "") Then
                        dr = dt.NewRow()
                        dr.Item("BCT_P_CODE") = code
                        dr.Item("BCT_P_NAME") = Name
                        dr.Item("BCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                        BCT_TIME = CLng(BCT_TIME) + Time
                        If (Load <> 0.0) Then
                            dr.Item("BCT_LOAD") = FormatNumber(Load, 3)
                            BCT_LOAD = CDbl(BCT_LOAD) + Load
                        Else
                            dr.Item("BCT_LOAD") = "-"
                        End If
                        If (DIsch <> 0.0) Then
                            dr.Item("BCT_DISCH") = FormatNumber(DIsch, 3)
                            BCT_DISCH = CDbl(BCT_DISCH) + DIsch
                        Else
                            dr.Item("BCT_DISCH") = "-"
                        End If

                        dr.Item("BCT_VOY") = count

                        dr.Item("STD_TIME") = STD_Time
                        dr.Item("ACT_TIME") = ACT_Time

                        dt.Rows.Add(dr)
                        dt.AcceptChanges()
                    End If
                    code = d.Item("Product_no")
                    count = 0
                    Name = CP & ". " & d.Item("Product_name")
                    Load = 0.0
                    DIsch = 0.0
                    Time = 0

                    STD_Time = d.Item("StandardTime").ToString()
                    ACT_Time = d.Item("ActualTime").ToString()

                    CP += 1
                End If
                If (d.Item("Product_Event") & "" = "L") Then
                    count += 1
                    If (d.Item("BU_TRUCK") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        Load += CDbl(d.Item("BU_TRUCK"))
                        BCT_VOY_LOAD = CInt(BCT_VOY_LOAD) + 1
                    End If
                Else
                    count += 1
                    If (d.Item("BU_TRUCK") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        DIsch += CDbl(d.Item("BU_TRUCK"))
                        BCT_VOY_DISCH = CInt(BCT_VOY_DISCH) + 1
                    End If
                End If
            Next
            If (code <> "") Then
                dr = dt.NewRow()
                dr.Item("BCT_P_CODE") = code
                dr.Item("BCT_P_NAME") = Name
                dr.Item("BCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                BCT_TIME = CLng(BCT_TIME) + Time
                If (Load <> 0.0) Then
                    dr.Item("BCT_LOAD") = FormatNumber(Load, 3)
                    BCT_LOAD = CDbl(BCT_LOAD) + Load
                Else
                    dr.Item("BCT_LOAD") = "-"
                End If
                If (DIsch <> 0.0) Then
                    dr.Item("BCT_DISCH") = FormatNumber(DIsch, 3)
                    BCT_DISCH = CDbl(BCT_DISCH) + DIsch
                Else
                    dr.Item("BCT_DISCH") = "-"
                End If

                dr.Item("BCT_VOY") = count

                dt.Rows.Add(dr)
                dt.AcceptChanges()
            End If
            code = ""
            count = 0
            Name = ""
            Load = 0.0
            DIsch = 0.0
            Time = 0
            CP = 1
            Dim cB As Integer = 0
            For Each d As DataRow In dtLi.Rows
                If (d.Item("Product_no") & "" <> code) Then
                    If (code <> "") Then
                        dt.Rows(cB).Item("LCT_P_CODE") = code
                        dt.Rows(cB).Item("LCT_P_NAME") = Name
                        dt.Rows(cB).Item("LCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                        LCT_TIME = CLng(LCT_TIME) + Time
                        If (Load <> 0.0) Then
                            dt.Rows(cB).Item("LCT_LOAD") = FormatNumber(Load, 3)
                            LCT_LOAD = CDbl(LCT_LOAD) + Load
                        Else
                            dt.Rows(cB).Item("LCT_LOAD") = "-"
                        End If
                        If (DIsch <> 0.0) Then
                            dt.Rows(cB).Item("LCT_DISCH") = FormatNumber(DIsch, 3)
                            LCT_DISCH = CDbl(LCT_DISCH) + DIsch
                        Else
                            dt.Rows(cB).Item("LCT_DISCH") = "-"
                        End If

                        dt.Rows(cB).Item("LCT_VOY") = count

                        dt.Rows(cB).Item("STD_TIME") = STD_Time
                        dt.Rows(cB).Item("ACT_TIME") = ACT_Time

                        dt.AcceptChanges()
                        cB += 1
                    End If
                    code = d.Item("Product_no")
                    count = 0
                    Name = CP & ". " & d.Item("Product_name")
                    Load = 0.0
                    DIsch = 0.0
                    Time = 0
                    CP += 1
                End If
                If (d.Item("Product_Event") & "" = "L") Then
                    count += 1
                    If (d.Item("LU_BLMT") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        Load += CDbl(d.Item("LU_BLMT"))
                        LCT_VOY_LOAD = CInt(LCT_VOY_LOAD) + 1

                    End If
                Else
                    count += 1
                    If (d.Item("LU_BLMT") & "" <> "") Then
                        Dim ts = DateDiff("n", d.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StartActual_Time"), d.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(d.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " 20" & d.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & d.Item("LU_StopActual_Time"))
                        Time += ts
                        DIsch += CDbl(d.Item("LU_BLMT"))
                        LCT_VOY_DISCH = CInt(LCT_VOY_DISCH) + 1

                    End If
                End If
            Next
            If (code <> "") Then
                dt.Rows(cB).Item("LCT_P_CODE") = code
                dt.Rows(cB).Item("LCT_P_NAME") = Name
                dt.Rows(cB).Item("LCT_TIME") = (Time \ 60) & ":" & (Time Mod 60).ToString("00")
                LCT_TIME = CLng(LCT_TIME) + Time
                If (Load <> 0.0) Then
                    dt.Rows(cB).Item("LCT_LOAD") = FormatNumber(Load, 3)
                    LCT_LOAD = CDbl(LCT_LOAD) + Load
                Else
                    dt.Rows(cB).Item("LCT_LOAD") = "-"
                End If
                If (DIsch <> 0.0) Then
                    dt.Rows(cB).Item("LCT_DISCH") = FormatNumber(DIsch, 3)
                    LCT_DISCH = CDbl(LCT_DISCH) + DIsch
                Else
                    dt.Rows(cB).Item("LCT_DISCH") = "-"
                End If

                dt.Rows(cB).Item("LCT_VOY") = count

                dt.Rows(cB).Item("STD_TIME") = STD_Time
                dt.Rows(cB).Item("ACT_TIME") = ACT_Time

                dt.AcceptChanges()
                cB += 1
            End If
        End If
        Return dt
    End Function

    Private Function CreateData() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("LCT_P_CODE", GetType(String))
        dt.Columns.Add("LCT_P_NAME", GetType(String))
        dt.Columns.Add("LCT_TIME", GetType(String))
        dt.Columns.Add("LCT_LOAD", GetType(String))
        dt.Columns.Add("LCT_DISCH", GetType(String))
        dt.Columns.Add("LCT_VOY", GetType(String))
        dt.Columns.Add("BCT_P_CODE", GetType(String))
        dt.Columns.Add("BCT_P_NAME", GetType(String))
        dt.Columns.Add("BCT_TIME", GetType(String))
        dt.Columns.Add("BCT_LOAD", GetType(String))
        dt.Columns.Add("BCT_DISCH", GetType(String))
        dt.Columns.Add("BCT_VOY", GetType(String))
        dt.Columns.Add("STD_TIME", GetType(String))
        dt.Columns.Add("ACT_TIME", GetType(String))
        dt.AcceptChanges()
        Return dt
    End Function

    Private Function GetNameMonth(ByVal Month As String) As String
        Try
            Select Case (CInt(Month).ToString("00"))
                Case "01"
                    Return "Jan"
                Case "02"
                    Return "Feb"
                Case "03"
                    Return "Mar"
                Case "04"
                    Return "Apr"
                Case "05"
                    Return "May"
                Case "06"
                    Return "Jun"
                Case "07"
                    Return "Jul"
                Case "08"
                    Return "Aug"
                Case "09"
                    Return "Sep"
                Case "10"
                    Return "Oct"
                Case "11"
                    Return "Nov"
                Case "12"
                    Return "Dec"
                Case Else
                    Return ""
            End Select
        Catch ex As Exception
            Return Month
        End Try

    End Function
End Class